home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / bin / example / oogl.c < prev    next >
C/C++ Source or Header  |  1993-09-08  |  2KB  |  82 lines

  1. /* oogl.c */
  2. /* geomview communication code */
  3. /* Charlie Gunn & Tamara Munzner */
  4. /* 9/92 */
  5.  
  6. #include <stdio.h>
  7. #include "geom.h"
  8. #include "meshflag.h"
  9.  
  10. FILE *f = stdout;
  11. static char *getline(char *s);
  12. Begin_OOGL()
  13. {
  14.   
  15.   fprintf(f, "(geometry example { : exhandle })\n");
  16.   fprintf(f, "(echo 'caughtup\n')");
  17.   fflush(f);
  18. }
  19.  
  20. UpdateOOGL(x_size, y_size, gridunit, data)
  21.      int x_size, y_size;
  22.      float gridunit;
  23.      float data[];
  24. {
  25.         register int    x,y,k;
  26.         Point3  *points;
  27.         Geom *mesh;
  28.     char line[80];
  29.     char *caughtup;
  30.     if (caughtup = fgets(line, 10, stdin)) {
  31.       points = OOGLNewN(Point3, x_size*y_size);
  32.       
  33.       
  34.       for (k = 0, y=0; y<y_size; ++y)
  35.         {
  36.           for (x=0; x<x_size; ++x, ++k)
  37.                 {
  38.           points[k].x = x*gridunit;
  39.           points[k].y = y*gridunit;
  40.           points[k].z = data[k];
  41.                 }
  42.         }
  43.       mesh = GeomCreate("mesh", 
  44.                 CR_NOCOPY, /* don't copy the points */
  45.                 CR_FLAG, MESH_Z, 
  46.                 CR_NU, x_size, 
  47.                 CR_NV, y_size, 
  48.                 CR_POINT, points,
  49.                 CR_END);
  50.       
  51.       fprintf(f, "(read geometry { define exhandle \n");
  52.       GeomFSave(mesh, f, NULL);
  53.       fprintf(f, "})\n");
  54.       fprintf(f, "(echo 'caughtup\n')");
  55.       fflush(f);
  56.       OOGLFree(mesh);
  57.     }
  58. }
  59.  
  60.  
  61.  
  62. /* Stolen from Mark Phillips' Hinge module */
  63. static char *getline(char *s)
  64. {
  65.   static char *p;
  66.   char *first;
  67.  
  68.   if (s != NULL) {
  69.     p = s;
  70.   } else {
  71.     *p = '\n';
  72.   }
  73.   ++p;
  74.   first = p;
  75.   while (*p != '\n' && *p != '\0') ++p;
  76.   if (*p == '\n') {
  77.     *p = '\0';
  78.     return first;
  79.   }
  80.   return NULL;
  81. }
  82.